package model.admin;

import java.sql.SQLException;
import java.util.List;

import model.letter.LetterVO;
import model.member.MemberVO;

import com.ibatis.sqlmap.client.SqlMapClient;

public class AdminDao {
	private SqlMapClient sqlMapClient;

	public AdminDao(SqlMapClient sqlMapClient) {
		this.sqlMapClient = sqlMapClient;
	}

	public List<NoticeBoardVO> noticeBoardList() throws SQLException {

		return sqlMapClient.queryForList("notice.noticeBoardList");
	}

	public int writeNotice(NoticeBoardVO nvo) throws SQLException {
		return (Integer) sqlMapClient.insert("notice.writeNotice", nvo);
	}

	public void deleteNoticeBoard(int no) throws SQLException {
		sqlMapClient.delete("notice.deleteNoticeBoard", no);

	}

	public void updateNoticeBoardContent(NoticeBoardVO nvo) throws SQLException {
		sqlMapClient.update("notice.updateNoticeBoardContent", nvo);
	}

	public NoticeBoardVO getContent(NoticeBoardVO nvo) throws SQLException {

		return (NoticeBoardVO) sqlMapClient.queryForObject("notice.getContent",
				nvo);
	}

	public NoticeBoardVO getNotice(NoticeBoardVO nvo) throws SQLException {
		return (NoticeBoardVO) sqlMapClient.queryForObject("notice.getNotice",
				nvo);
	}

	public List<NoticeBoardVO> noticeList(String pageNo) throws SQLException {
		return sqlMapClient.queryForList("notice.noticeList", pageNo);
	}
    public void updateNoticeCount(NoticeBoardVO nvo) throws SQLException{
    	sqlMapClient.update("notice.updateNoticeCount",nvo);
    }
	public List<MemberVO> allMember(String pageNo) throws SQLException {
		return sqlMapClient.queryForList("admin.allMember", pageNo);
	}

	public MemberVO findMemberById(MemberVO mvo) throws SQLException {
		return (MemberVO) sqlMapClient.queryForObject("admin.findMemberById",
				mvo);
	}

	public void updateUserLevel(MemberVO mvo) throws SQLException {
		sqlMapClient.update("admin.updateUserLevel", mvo);
	}
	//멤버 강제탈퇴 member의 deleteMember로 대체됨
	/*public void removeMember(MemberVO mvo) throws SQLException {
		sqlMapClient.delete("admin.removeMember", mvo);
	}*/

	public Integer getTotalNotice() throws SQLException {
		return (Integer) sqlMapClient.queryForObject("notice.getTotalNotice");
	}

	public int getTotalMember() throws SQLException {
		return (Integer) sqlMapClient.queryForObject("admin.getTotalMember");
	}

	public MemberVO idExist(String id) throws SQLException {
		return (MemberVO) sqlMapClient.queryForObject(
				"optionalService.idExist", id);
	}

	public void optionalServiceRequest(OptionalServiceVO osvo)
			throws SQLException {
		int no = (int) sqlMapClient.insert(
				"optionalService.optionalServiceRequest", osvo);
		osvo.setOptionalNo(no);
		System.out.println("서비스 신청 왼료됨.." + osvo);
	}

	public OptionalServiceVO requestChecked(MemberVO mvo) throws SQLException {
		return (OptionalServiceVO) sqlMapClient.queryForObject(
				"optionalService.requestChecked", mvo);
	}

	public void requestM(OptionalServiceVO osvo) throws SQLException {
		sqlMapClient.update("optionalService.requestM", osvo);
		System.out.println("requestM 승인 완료");
	}

	public void requestW(OptionalServiceVO osvo) throws SQLException {
		sqlMapClient.update("optionalService.requestW", osvo);
		System.out.println("requestW 승인 완료");
	}

	public int requestNoById(String id) throws SQLException {
		return (int) sqlMapClient.queryForObject(
				"optionalService.requestNoById", id);
	}

	public boolean duplicationServiceId(String id) throws SQLException {
		boolean flag=false;
		if(sqlMapClient.queryForObject("optionalService.duplicationServiceId", id) != null){
			flag=true;
		}
		return flag;
		}
	public List<OptionalServiceVO> requestManagement() throws SQLException {
		return sqlMapClient.queryForList("admin.requestManagement");
	}

	public OptionalServiceVO requestConfirm(OptionalServiceVO osvo) throws SQLException {
		return (OptionalServiceVO) sqlMapClient.queryForObject("admin.requestConfirm",osvo);
	}

	public void adminAllow(OptionalServiceVO osvo) throws SQLException {
		sqlMapClient.update("admin.adminAllow",osvo);
	}

	public void requestDelete(String id) throws SQLException {
		sqlMapClient.delete("admin.requestDelete", id);
		
	}


}
